<?php
$_SESSION['steps'][$_GET['action']] = false;
if($_SESSION['index']=='')
{
	displayError('Une erreur interne s\'est produit (perte du fichier index.xml)');
}

$setup = new SimpleXMLElement($_SESSION['index']);

$ch="";
if(isset($_GET['post']) && $_GET['post']==1)
{
	$_SESSION['conf_root']['login'] = trim($_POST['txt_login']);
	$_SESSION['conf_root']['password'] = trim($_POST['txt_password']);
	
	if($_SESSION['conf_root']['login']=='')
	{
		$ch  .= '<span class="install_message_error">Le champ Login est obligatoire...</span><br>';
	}
	if($_SESSION['conf_root']['password']=='')
	{
		$ch  .= '<span class="install_message_error">Le mot de passe  obligatoire...</span><br>';
	}
	if($ch=='')
	{
		if(trim($_POST['txt_password'])!=trim($_POST['txt_confirm']))
		{
			$ch  .= '<span class="install_message_error">Erreur sur la confirmation du mot de passe</span><br>';
		}
		elseif($_SESSION['conf_root']['password_ok']!='' && $_SESSION['conf_root']['password_ok']!=md5($_SESSION['conf_root']['password']))
		{
			$ch  .= '<span class="install_message_error">Vous devez préciser le même mot de passe que l\'installation précédente</span><br>';
		}
	}
	if($ch=='')
	{
		$_SESSION['steps']['conf_root'] = true;
?>
conf_root_next_fct()
<?php
		die();
	}
}
else
{
	if(!isset($_SESSION['conf_root']['login']))
	{
		$_SESSION['conf_root']['login'] = 'root';
		$_SESSION['conf_root']['password'] = '';
	}
}

if($ch!='') $ch.='<br>';
$ch.=	'<form id="form_conf_root" action="javascript:document.getElementById(\'install_next\').onclick()">
<label for="txt_login" class="form">Login</label><input type="text" class="text" id="txt_login" name="txt_login" value="'.htmlspecialchars($_SESSION['conf_root']['login']).'"><br>
<label for="txt_password" class="form">Password</label><input type="password" class="text" id="txt_password" name="txt_password"><br>
<label for="txt_confirm" class="form">Confirmation</label><input type="password" class="text" id="txt_confirm" name="txt_confirm"><br>
<input type="image" src="./temp/setup_px.gif">
</form>
';


?>
document.getElementById('install_content_intro').innerHTML = 'Veuillez saisir les paramètres de connxion a la base de données. Si vous n\'êtes pas sur de vous, demandez a votre administrateur.';
document.getElementById('install_content_data').innerHTML = '<?php echo strToJs($ch)?>'
<?php
displayButtons();
?>

conf_root_next_fct = document.getElementById('install_next').onclick;
document.getElementById('install_next').onclick=function()
{
	document.getElementById('install_next').disabled = true;
	document.getElementById('install_back').disabled = true;
	
	document.getElementById('install_loading').style.display="block"

	ajax.sendAsync(page+'?action=conf_root&post=1&uid='+new Date().getTime(), function(datas)
	{
		document.getElementById('install_loading').style.display="none"
		document.getElementById('install_next').disabled = false;
		document.getElementById('install_back').disabled = false;
		evalAjax(datas)
	}, ajax.buildDatas(document.getElementById("form_conf_root")))
}